package com.gurumades.jsonform.client.forms;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class FieldsetWidget extends Composite {

	private static final Binder binder = GWT.create(Binder.class);

	interface Binder extends UiBinder<Widget, FieldsetWidget> {
	}
	
	@UiField DivElement description;
	@UiField FlowPanel content;
	@UiField Label title;
	@UiField Image header_img;
	
	@UiField DisclosurePanel panel;

	public FieldsetWidget() {
		initWidget(binder.createAndBindUi(this));
	}
	
	public void setDescription(String description) {
		this.description.setInnerHTML(description);
	}
	
	public void setTitle(String title, String url) {
		this.title.setText(title);
		if (url != null) {
			this.header_img.setUrl(url);
			this.header_img.setAltText(title);
		}
	}

	
	public void addFormItem(Widget formItem){
		content.add(formItem);
	}
	
	public DisclosurePanel getPanel() {
		return panel;
	}

}
